'use strict'
import {
  Model,
  DataTypes,
  InferAttributes,
  InferCreationAttributes,
  CreationOptional,
} from 'sequelize'
import dayjs from 'dayjs'
import { Models } from '../type'
import sequelize from '.'

class AttributeAttributeValue extends Model<
  InferAttributes<AttributeAttributeValue>,
  InferCreationAttributes<AttributeAttributeValue>
> {
  declare id: CreationOptional<number>
  declare attributeId: number
  declare attributeValueId: number
  declare createdAt: CreationOptional<Date>
  declare updatedAt: CreationOptional<Date>

  static associate(models: Models) {}
}
AttributeAttributeValue.init(
  {
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    attributeId: DataTypes.INTEGER,
    attributeValueId: DataTypes.INTEGER,
    createdAt: {
      type: DataTypes.DATE,
      get() {
        return this.getDataValue('createdAt')
          ? dayjs(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss')
          : null
      },
    },
    updatedAt: {
      type: DataTypes.DATE,
      get() {
        return this.getDataValue('updatedAt')
          ? dayjs(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm:ss')
          : null
      },
    },
  },
  {
    sequelize,
    modelName: 'AttributeAttributeValue',
  },
)

export default AttributeAttributeValue
